package com.eshop.we.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.eshop.we.account.entity.Account;
import com.eshop.we.accountdetail.dto.AccountDetailDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * 用户账户 Mapper 接口
 * </p>
 *
 * @author anonymity
 * @since 2018-07-06
 */
@Mapper
@Component
public interface AccountMapper extends BaseMapper<Account> {

    @Select("<script>" +
            " select u.real_name as name ,u.mobile  ,s.name as schoolName, a.* ,d.* " +
            " from account_detail  d " +
            " left join account a on a.id= d.account_id " +
            " left join user u on u.id=a.user_id " +
            " left join school s on u.school_id=s.id"+
            " where 1=1 "+
            " <if test='name!=null '>"+
            " and u.real_name like     CONCAT(CONCAT('%', #{name}), '%') "+
            " </if>"+
            "<if test='mobile!=null '>"+
            " and u.mobile like  CONCAT(CONCAT('%', #{mobile}), '%')"+
            " </if>"+
            " <if test='start!=null '>"+
            " and d.ctime &gt;=  #{start} "+
            " </if>"+
            " <if test='end!=null '>"+
            " and d.ctime &lt;=  #{end} "+
            " </if> "+
            " </script>")
    List<AccountDetailDto> selectAccountPage(Page<AccountDetailDto> page, @Param("name") String name,@Param("mobile")  String mobile, @Param("start") Long  start, @Param("end") Long end);
}
